define(function (require) {

    require('../../../c/base/index');

    require('../../../c/nav/index');

    var firstTime = true, infoFirstTime = true;

    var frezzBank = {
        _day: "",
        init: function () {
            //初始化菜单选中效果
            $(".fa-circle-o").each(function () {
                if ($(this).parents("a").text() == "追款冻结") {
                    $(this).parents("a").parents("li").addClass("active");
                }
            });
            this.initValidator();
            this.bindEvent();
        },
        /**
         * 表单验证初始化
         */
        initValidator: function () {
            $('#frezz_from').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                }
            });
            $('#debit_from').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                }
            });
            $('#bank3ToBank4_from').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                }
            });
        },
        bindEvent: function () {
            var self = this;
            $("#frezz").on('click', function () {
                self.frezzingShop();
            });
            $("#unfrezz").on('click', function () {
                self.unFrezzingShop();
            });
            $("#debit").on('click', function () {
                self.debit();
            });
            $("#debit_frezz").on('click', function () {
                self.frezzingMoney();
            });
            $("#bank3ToBank4").on('click', function () {
                self.bank3ToBank4();
            });
            $("#file").fileupload({
                url: CRM.getOuterUrl('/centralbank/caiwu/debitBatch'),//文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{bankDisburseRecordId:_id},//如果需要额外添加参数可以在这里添加
                done: function (e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        CRM.showDialog(req.result.message);
                        $('#table').DataTable().ajax.reload();
                    } else {
                        CRM.showDialog(req.result.message);
                    }

                }
            });
        },
        /**
         * 冻结店铺
         */
        frezzingShop:function(){
            $("#frezz_from").data('bootstrapValidator').validate();
            if (!$("#frezz_from").data('bootstrapValidator').isValid()) {
                return false
            }
            var _data = {};
            $($("#frezz_from").serializeArray()).each(function () {//获取查询条件
                _data[this.name] = this.value;
            });
            CRM.request({
                "type": 'GET',
                "url": CRM.getOuterUrl('/centralbank/caiwu/frezzingShop'),
                "dataType": "json",
                contentType: "application/x-www-form-urlencoded",
                xhrFields: {
                    withCredentials: true
                },
                "data": _data,
                contentType: "application/json",
                "success": function (req) {
                    if (req.status) {
                        CRM.showDialog(req.message);
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        },
        /**
         * 解冻店铺
         */
        unFrezzingShop:function(){
            $("#frezz_from").data('bootstrapValidator').validate();
            if (!$("#frezz_from").data('bootstrapValidator').isValid()) {
                return false
            }
            var _data = {};
            $($("#frezz_from").serializeArray()).each(function () {//获取查询条件
                _data[this.name] = this.value;
            });
            CRM.request({
                "type": 'GET',
                "url": CRM.getOuterUrl('/centralbank/caiwu/unFrezzingShop'),
                "dataType": "json",
                contentType: "application/x-www-form-urlencoded",
                xhrFields: {
                    withCredentials: true
                },
                "data": _data,
                contentType: "application/json",
                "success": function (req) {
                    if (req.status) {
                        CRM.showDialog(req.message);
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        },
        /**
         * 追款
         * @returns {boolean}
         */
        debit:function(){
            $("#debit_from").data('bootstrapValidator').validate();
            if (!$("#debit_from").data('bootstrapValidator').isValid()) {
                return false
            }
            var _data = {};
            $($("#debit_from").serializeArray()).each(function () {//获取查询条件
                _data[this.name] = this.value;
            });
            CRM.request({
                "type": 'GET',
                "url": CRM.getOuterUrl('/centralbank/caiwu/debit'),
                "dataType": "json",
                contentType: "application/x-www-form-urlencoded",
                xhrFields: {
                    withCredentials: true
                },
                "data": _data,
                contentType: "application/json",
                "success": function (req) {
                    if (req.status) {
                        CRM.showDialog(req.message);
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        },
        /**
         * 冻结金额
         * @returns {boolean}
         */
        frezzingMoney:function(){
            $("#debit_from").data('bootstrapValidator').validate();
            if (!$("#debit_from").data('bootstrapValidator').isValid()) {
                return false
            }
            var _data = {};
            $($("#debit_from").serializeArray()).each(function () {//获取查询条件
                _data[this.name] = this.value;
            });
            _data.freezingFee = _data.fee;
            CRM.request({
                "type": 'GET',
                "url": CRM.getOuterUrl('/centralbank/caiwu/frezzingMoney'),
                "dataType": "json",
                contentType: "application/x-www-form-urlencoded",
                xhrFields: {
                    withCredentials: true
                },
                "data": _data,
                contentType: "application/json",
                "success": function (req) {
                    if (req.status) {
                        CRM.showDialog(req.message);
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        },
        /**
         * 一键3.0账单到4.0
         */
        bank3ToBank4:function(){
            $("#bank3ToBank4_from").data('bootstrapValidator').validate();
            if (!$("#bank3ToBank4_from").data('bootstrapValidator').isValid()) {
                return false
            }
            var _data = {};
            $($("#bank3ToBank4_from").serializeArray()).each(function () {//获取查询条件
                _data[this.name] = this.value;
            });
            CRM.request({
                "type": 'GET',
                "url": CRM.getOuterUrl('/centralbank//bill/bank3ToBank4'),
                "dataType": "json",
                contentType: "application/x-www-form-urlencoded",
                xhrFields: {
                    withCredentials: true
                },
                "data": _data,
                contentType: "application/json",
                "success": function (req) {
                    if (req.status) {
                        CRM.showDialog(req.message);
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        }

    };


    frezzBank.init();
});